﻿// Copyright (C) Norsolutions GmbH
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Reng van Oord
// Created:    2010.05.05


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sherwood.Mvc.Html
{
    /// <summary>
    /// Provides a culture list source for an ASP.Net MVC drop down list.
    /// Value is the .Net culture code and text is the name in English.
    /// </summary>
    public class ShortCultureSelectList
    {
        public static List<SelectListItem> GetList(object selectedValue, bool translate)
        {
            if (selectedValue == null)
            {
                selectedValue = "en-US";
            }
            string[] values = new string[] { 
"nl-NL","Dutch",
"en-US","English",
"fr-FR","French",
"fi-FI","Finnish",
"de-DE","German",
"nb-NO","Norwegian"
 };

            List<SelectListItem> items = new List<SelectListItem>();

            for (int i = 0; i < values.Length; i = i + 2)
            {
                SelectListItem item = new SelectListItem();
                if (translate)
                    item.Text = "[!" + values[i + 1] + "!]";
                else
                    item.Text = values[i + 1];
                item.Value = values[i];
                item.Selected = selectedValue != null && values[i].Equals(selectedValue.ToString(), StringComparison.OrdinalIgnoreCase);
                items.Add(item);
            }

            return items;
        }
    }
}
